package gui.initiatives;

import gui.DateTimePanel;
import gui.EarthPanel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import simulation.initiatives.AbstractEngine;
import common.Constants;

public class ClockPullListener implements ActionListener {
  private DateTimePanel pnlDateTime;
  private EarthPanel pnlEarth;
  private AbstractEngine engine;
  
  private int simTimeStep; //in milliseconds
  private float sunDegStep; //derived from simTimeStep to update the display of the sun in the earth panel
  
  public ClockPullListener(DateTimePanel pnlDateTime, EarthPanel pnlEarth, AbstractEngine engine) {
    this.pnlDateTime = pnlDateTime;
    this.pnlEarth = pnlEarth;
    this.engine = engine;
    setSimTimeStep(Constants.DEFAULT_SIM_TIME_STEP);
  }
  
  public void setSimTimeStep(int minutes) {
    simTimeStep = minutes * 60 * 1000;
    sunDegStep = Constants.DEG_PER_MIN * (float)minutes;
  }
  
  public void actionPerformed(ActionEvent e) {
    pnlEarth.updateGrid(engine);        
    pnlEarth.moveSunPosition(sunDegStep);
    pnlDateTime.increment(simTimeStep);
  }

}
